import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:ywn_app/contains/ThemeGlobal.dart';

import '../contains/ThemeGlobal.dart';

class CustomerSwiper extends StatelessWidget {
  int millisecond;
  bool autoplay;
  List<String> images;

  CustomerSwiper({Key key,this.autoplay = true, this.images, this.millisecond = 500}) : super(key: key);

  buildSwiperPagination() {
    // 分页指示器
    return SwiperPagination(
      //指示器显示的位置
      alignment: Alignment.bottomRight, // 位置 Alignment.bottomCenter 底部中间
      // 距离调整
      margin: const EdgeInsets.fromLTRB(0, 0, 15, 5),
      // 指示器构建
      builder: DotSwiperPaginationBuilder(
        // 点之间的间隔
          space: 2,
          // 没选中时的大小
          size: 5,
          // 选中时的大小
          activeSize: 5,
          // 没选中时的颜色
          color: Colors.black54,
          //选中时的颜色
          activeColor: Colors.white),
    );
  }

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(10),
      child: Swiper(
          itemBuilder: (BuildContext context, int index) {
            return Image.network(images[index], fit: BoxFit.cover);
          },
          itemCount: images.length,
          scrollDirection: Axis.horizontal,
          duration: millisecond,
          autoplay: autoplay,
          loop: true,
          onTap: (index) {
            /*Navigator.push(context, MaterialPageRoute(builder: (_) {
              return DetailScreen();
            }
            ));*/
            print(index);
          },
          pagination: buildSwiperPagination(),
          autoplayDisableOnInteraction: true),
    );
  }
}
